<template>
	<div class="aid">
		<div class="base">
			<p class="fixed-top">
				{{ text.type=='add' ? '添加问卷问题选项' : '修改问卷问题选项' }}
				<a-icon @click="closeFunction" type="close" />
			</p>
			<div class="main" id="new_message">
				<a-form-model ref="ruleForm" :model="form" :rules="rules">
				
					<a-form-model-item label="名称" prop="Name"><a-input v-model="form.Name" /></a-form-model-item>
					<a-form-model-item label="分值" prop="Score">
						<a-input-number :min="0" :precision="0" v-model="form.Score"  />
					</a-form-model-item>
					<a-form-model-item label="是否正确答案" prop="IsCorrectAnswer">
						<a-radio-group v-if="radioStatus" v-model="form.IsCorrectAnswer"  name="radioGroup" @change="radioChange"  >
							<a-radio :key="1" :value="true">是</a-radio>
							<a-radio :key="2"  :value="false">否</a-radio>
						</a-radio-group>
					</a-form-model-item>
					<a-form-model-item label="" class="fixed-bottom">
						<a-button type="primary" @click="handleSubmit">{{ text.type=='add' ? '确认添加' : '确认修改' }}</a-button>
						<a-button style="margin-left: 10px;" @click="closeFunction">取消</a-button>
					</a-form-model-item>
				</a-form-model>
			</div>
		</div>
	</div>
</template>

<script>
import moment from 'moment';
import { ManageEvaluationSubjectItemDoAdd, ManageEvaluationSubjectItemDoUpdate, DoGetDetailStudent } from '@/api/follow';
export default {
	props: {
		text: Object,
		ClassList: Array,
		DepartCodeList: Array
	},
	watch: {
		text: function(text) {
			// console.log(JSON.stringify(text));
			// console.log(JSON.stringify(text).ID);
			if (text.type=='add') {
				this.form=text
			} else {
				// this.GetDetailStudent(text)
				 this.form = text;
				// this.form.Name=text.Name;
				// this.form.Score=text.Score;
				// this.form.ID=text.ID;
				// this.form.IsCorrectAnswer=text.IsCorrectAnswer;
				//
				// console.log(text)
			}
		}
	},
	data() {
		return {
			radioStatus:false,
			gradeYear: null,
			yearPickShow: false,
			loading: false,
			formLayout: 'horizontal',
			form: this.$form.createForm(this, {
				name: 'coordinated'
			}),
			form: {
				Name:'',
				Score:'',
				IsCorrectAnswer:null,
			},
			rules: {
				Name: [
					{
						required: true,
						message: '请输入选项名称',
						trigger: 'change'
					}
				],
				Score: [
					{
						required: true,
						message: '请输入分值',
						trigger: 'change'
					}
				],
				
			}
		};
	},
	created() {
		this.radioStatus=true
	},
	methods: {
		radioChange(e){
			console.log(e)
			this.radioStatus=false;
			this.radioStatus=true;
			 // this.$set(this.form,'IsCorrectAnswer',e.target.value)
			this.form.IsCorrectAnswer=e.target.value;
			// let that=this;
			// that.$nextTick(() => {
			// 	setTimeout(function() {
			// 		that.form.setFieldsValue({
			// 			Type: e.target.value,
			// 		});
			// 	}, 300);
			// })
		},
		filterOption(input, option) {
			return option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0;
		},
		moment,
		handleOpenChange(status) {
			this.yearPickShow = status;
		},
		handlePanelChange(value, mode) {
			this.gradeYear = moment(value).format('YYYY');
			this.form.Grade = this.gradeYear;
			this.yearPickShow = false;
		},
		yearChange(date, dateString) {
			if (!date) {
				this.gradeYear = null;
				this.form.Grade = this.gradeYear;
			}
		},
		closeFunction(data) {
			this.$emit('closeFun', data);
			this.form = {};
			this.gradeYear = null;
			this.fileList = [];
		},
		handleSubmit(e) {
			console.log(this.text);
			this.$refs.ruleForm.validate(async valid => {
				if (valid) {
					let data = this.form;
					data.HeadMasterEvaluationID=this.$route.query.ID;
					let res = {};
					if (this.text.type=='add') {
						res = await ManageEvaluationSubjectItemDoAdd(data);
					} else {
						res = await ManageEvaluationSubjectItemDoUpdate(data);
					}
					if (res.data.code === 0) {
						this.$message.success(res.data.msg);
						this.closeFunction('1');
					} else {
						this.$message.error(res.data.msg);
					}
				} else {
					return false;
				}
			});
		}
	}
};
</script>

<style lang="less" scoped>
/deep/.ant-form-item {
	margin: 20px 50px;
}
/deep/.ant-form-item-label {
	width: 100px;
	overflow: hidden;
	white-space: nowrap;
	text-overflow: ellipsis;
	text-align: right;
}
/deep/.ant-form-item-control-wrapper {
	flex: 1;
}
</style>
